package com.promis.party.ui.home.message;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.promis.compat.StatusBarCompat;
import com.promis.party.R;
import com.promis.party.helper.UIHepler;

public class MessageActivity extends AppCompatActivity{
    private String[] tabNames = new String[]{"今日通知","昨日通知","更多"};

    private TabLayout tblyContainer;
    private ViewPager vpgvContainer;
    private FragmentPagerAdapter adapter;
    private LinearLayout llyvPublish;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        StatusBarCompat.translucentStatusBar(this);
        StatusBarCompat.blackTextStatusBar(this);
        UIHepler.goBack(this,R.id.activity_message_imgv_back);
        tblyContainer = findViewById(R.id.activity_message_tbly_container);
        vpgvContainer = findViewById(R.id.activity_message_vpgv_container);
        llyvPublish = findViewById(R.id.activity_message_llyv_publish);
        initData();
        initListener();
    }

    private void initData(){
        tblyContainer.setupWithViewPager(vpgvContainer);
        adapter = new FragmentPagerAdapter(getSupportFragmentManager());
        vpgvContainer.setAdapter(adapter);
        for (int i = 0; i < tblyContainer.getTabCount() ; i++) {
            TabLayout.Tab tab = tblyContainer.getTabAt(i);
            tab.setText(adapter.getPageTitle(i));
        }
        UIHepler.setTabLayoutIndicator(tblyContainer, 25, 25);
    }

    private void initListener(){
        llyvPublish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getBaseContext(),PublishMessageActivity.class);
                startActivity(intent);
            }
        });
    }
    private class FragmentPagerAdapter extends FragmentStatePagerAdapter {

        public FragmentPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return MessageFragment.newInstance();
            } else if (position == 1) {
                return MessageFragment.newInstance();
            } else if (position == 2) {
                return MessageFragment.newInstance();
            }
            return null;
        }

        @Override
        public int getCount() {
            return tabNames.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabNames[position];
        }
    }
}
